package com.byzk.invoice.xml.Doc_0;

import com.byzk.invoice.util.DocumentUtil;
import org.dom4j.*;

import java.io.File;

/**
 * 创建DocumentRes.xml.
 *
 * @author 康鹏 2020-05-20
 */
public class DocumentRes {

    /**
     * 创建Doc_0/DocumentRes.xml.
     * @param documentResXmlPath DocumentRes.xml存放路径
     * @throws Exception Exception
     */
    public static void createDocumentResXml(String documentResXmlPath) throws Exception {

        Namespace namespace = new Namespace("ofd", "http://www.ofdspec.org/2016");
        //创建外层<ofd:Res />
        Element rootElt = DocumentHelper.createElement(new QName("Res", namespace));
        rootElt.addAttribute("BaseLoc", "Res");
        //创建<ofd:MultiMedias />
        Element multiMediasElt = rootElt.addElement("ofd:MultiMedias");
        //创建<ofd:MultiMedia />
        Element multiMediaElt = multiMediasElt.addElement("ofd:MultiMedia");
        multiMediaElt.addAttribute("ID", "102");
        multiMediaElt.addAttribute("Type", "Image");
        multiMediaElt.addAttribute("Format", "GBIG2");
        //创建<ofd:MediaFile />
        Element mediaFileElt = rootElt.addElement("ofd:MediaFile");
        mediaFileElt.setText("image_102.jb2");

        Document document = DocumentHelper.createDocument(rootElt);
        DocumentUtil.writer(document, documentResXmlPath + File.separator + "Doc_0"
                + File.separator + "DocumentRes.xml", true);
    }

}
